<template>
  <div class="intervention">
    <el-container>
      <el-input
        style="width: 20%"
        placeholder="预约档案号/姓名"
        v-model="parameter.content"
        clearable
      ></el-input>
      <el-button
        type="primary"
        size="mini"
        @click="onSubmit"
        icon="el-icon-search"
        round
        >查询</el-button
      >
    </el-container>
    <el-table
      style="width: 100%"
      align="center"
      v-loading="loading"
      element-loading-text="拼命加载中"
      element-loading-spinner="el-icon-loading"
     :data="AllUser">
      <el-table-column label="预约档案号" prop="torder.toOrderno" width="120">
      </el-table-column>
      <el-table-column label="姓名" prop="name" width="100"> </el-table-column>
      <el-table-column label="性别" prop="sex" width="100">
        <template slot-scope="scope">
          <span v-if="(scope.row.sex = 0)"> 女 </span>
          <span v-if="(scope.row.sex = 1)"> 男 </span>
        </template>
      </el-table-column>
      <el-table-column label="年龄" prop="age" width="100"> </el-table-column>
      <el-table-column label="手机号" prop="phonenumber" width="150">
      </el-table-column>
      <el-table-column label="邮箱" prop="email" width="150"> </el-table-column>
      <el-table-column label="建档时间" prop="createtime" width="270">
      </el-table-column>
      <el-table-column label="操作" width="240">
        <template slot-scope="scope">
          <el-button
            type="primary"
            size="mini"
            @click.native="update(scope.row)"
            icon="el-icon-edit"
          >
            制定方案
          </el-button>
          <!-- <el-button type="danger"  size="mini" icon="el-icon-delete">
            删除
          </el-button> -->
        </template>
      </el-table-column>
    </el-table>
    <el-pagination
      :total="total"
      @size-change="handleSizeChange"
      @current-change="handleCurrentChange"
      :current-page.sync="parameter.page"
      :page-sizes="[2, 5, 10, 20]"
      :pager-count="9"
      background
      :page-size.sync="parameter.num"
      layout="total, sizes, prev, pager, next, jumper"
    >
    </el-pagination>
  </div>
</template>

<script>
import Vue from "vue";
import axios from "axios";
export default Vue.extend({
  data() {
    return {
      loading: true,
      AllUser: [],
      parameter: {
        page: 1,
        num: 5,
        content: "",
        janID: "",
      },
      total: 0,
    };
  },
  methods: {
    handleSizeChange() {
      this.load();
    },
    handleCurrentChange() {
      this.load();
    },
    onSubmit() {
      this.load();
    },
    update(Scope){
      console.log(Scope)
      axios
        .post("/api/lqHealth/chaTinterpose", {tmerber:Scope.torder.toOrderno}).then(res=>{
            if(res.data>0){
            this.$router.push({path:"/home/DecisionMaker?breadcrunmbName=健康干预,干预方案,方案详情",query:{user_scpoe:'user_scpoe',value:Scope}})
            }else{
                  this.$message({
                type: "error",
                message: "改用户已存在但是还未被健康管理师分类!",
              });
            }
        })
    },
    load() {
      axios
        .get(
          "/api/TRoleAllList?name=" +
            JSON.parse(sessionStorage.getItem("user")).username
        )
        .then((res) => {
          if (res.data.name == "系统管理员") {
            axios
              .post("/api/lqHealth/selectAllTmerber", this.parameter)
              .then((res) => {
                console.log(res);
                this.AllUser = res.data.list;
                this.parameter.page = res.data.pageNum;
                this.parameter.num = res.data.pageSize;
                this.total = res.data.total;

                //加载样式
                setTimeout(() => {
                  this.loading = false;
                }, 1000);
              });
          } else {
            axios.post("/api/lqHealth/selectThByname",{name: JSON.parse(sessionStorage.getItem("user")).username}).then(rp=>{
             this.parameter.janID=rp.data.healthMgrId
             console.log(this.parameter)
            axios
              .post("/api/lqHealth/selectByJiangKan", this.parameter)
              .then((res) => {
                console.log(res);
                this.AllUser = res.data.list;
                this.parameter.page = res.data.pageNum;
                this.parameter.num = res.data.pageSize;
                this.total = res.data.total;

                //加载样式
                setTimeout(() => {
                  this.loading = false;
                }, 1000);
              });
            })
          }
        });
    },
    success() {
      this.$message({
        type: "success",
        message: "已确认分类信息!",
      });
    },
  },
  created() {
    this.load();
  },
});
</script>

  <style scoped>
</style>